﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.Web.UI.WebControls;
using WCSFContrib.ECommerceCatalog.Admin.Views;
using WCSFContrib.ECommerceCatalog.BusinessEntities;
using WCSFContrib.ECommerceCatalog.BusinessEntities.Enums;

namespace WCSFContrib.ECommerceCatalog.Admin.Views
{
    public partial class Admin_Default : Microsoft.Practices.CompositeWeb.Web.UI.Page, IDefaultView
    {
        private DefaultViewPresenter _presenter;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this._presenter.OnViewInitialized();
            }
            this._presenter.OnViewLoaded();
        }

        [CreateNew]
        public DefaultViewPresenter Presenter
        {
            set
            {
                this._presenter = value;
                this._presenter.View = this;
            }
        }

        protected void OrdersObjectContainerDataSource_Updated(object sender, ObjectContainerDataSourceStatusEventArgs e)
        {
            _presenter.OnEditOrder((Order)e.Instance);
        }

        #region IDefaultView Members

        public void ShowOrders(ICollection<Order> orders)
        {
            OrdersObjectContainerDataSource.DataSource = orders;
        }

        public int TotalOrdersCount
        {
            set
            {
                OrdersObjectContainerDataSource.TotalRowCount = value;

                ViewState["TotalOrdersCount"] = value;
            }
            get
            {
                return (int)(ViewState["TotalOrdersCount"] ?? 0);
            }
        }

        public void ShowUsers(MembershipUserCollection users)
        {
            UsersGridView.DataSource = users;
            UsersGridView.DataBind();
        }

        #endregion
    }
}